import React from 'react';
import BackToAuthenticateStyle from './BackToAuthenticate.less';
import { push } from 'react-router-redux';
import { connect } from 'react-redux';

export default class BackToAuthenticate extends React.Component {
  static propTypes = {
    name: React.PropTypes.string,
  };

  timer=null;
  
  state = {
  	//倒计时读秒
    countDown:5,

  };

  constructor(props) {
    super(props);
  };

  componentWillMount() {
    let { countDown } = this.state;
   	 this.timer = setInterval(()=>{
            this.setState({
              countDown:countDown--
            })
            if (countDown==0){
              this.handleBackToAuthenticate();
            }
      },1000);
  };
  //直接返回登录页面
  handleBackToAuthenticate = () => {
    let { dispatch } = this.props;
      clearInterval(this.timer);
    dispatch(push('app/authenticate'));
  };
  
  render() {
  	let { countDown } = this.state;
    return (
      <div className={BackToAuthenticateStyle.backToAuthenticate}>
        <p>密码修改成功,{countDown}秒后自动跳转回登录页面...</p>
        <a className="login-button" onClick={this.handleBackToAuthenticate}  href="javascript:void(0)">返回登录页面</a>
      </div>
    );
  }
}
export default connect((state) => state)(BackToAuthenticate);
